<%@ include file="/common/taglibs.jsp"%>
<head>
    <title><fmt:message key="devolucionclienteForm.title"/></title>
    <meta name="heading" content="<fmt:message key='devolucionclienteForm.heading'/>"/>
</head>
 
<spring:bind path="canjeform.*">
    <c:if test="${not empty status.errorMessages}">
    <div class="error">
        <c:forEach var="error" items="${status.errorMessages}">
            <img src="<c:url value="/images/iconWarning.gif"/>"
                alt="<fmt:message key="icon.warning"/>" class="icon"/>
            <c:out value="${error}" escapeXml="false"/><br />
        </c:forEach>
    </div>
    </c:if>
</spring:bind>

<form:form commandName="canjeform" method="post" action="canjeform.html" 
	onsubmit="return onFormSubmit(this)" id="canjeform">
<form:hidden id="idDocumentoMovArticulo" path="id"/>
<form:hidden id="stOperacionID" path="stOperacion"/>
<form:hidden id="coClienteID" path="coCliente"/>
<form:hidden id="stDocumentoMovArtID" path="stDocumentoMovArt"/>
<form:hidden id="coDocumentoMovCanjeID" path="coDocumentoMovCanje"/> 


<ul>
	<li class="buttonBar right">
		<c:set var="buttons">
            
            <input type="button" class="button" value="<fmt:message key="button.devolver"/>"
            id="btnDevolverID" name="btnDevolverName" onclick="devolucionCliente()"/>
            
			 <c:if var="iRpta" test="${esDevolucion == 'Y'}" >
			 	<input type="button" class="button" onclick="location.href='<c:url value="/devolucioncliente/devolucionclientelist.html"/>'"
			 	value="<fmt:message key="button.cancel"/>"/>
			 </c:if>
			 <c:if test="${iRpta!=true}">												
			 	<input type="button" class="button" onclick="location.href='<c:url value="/canje/canjelist.html"/>'"
		    	value="<fmt:message key="button.cancel"/>"/>
			 </c:if>
		    
		    
        </c:set>
        <c:out value="${buttons}" escapeXml="false"/>
	</li>
	
	 <c:if test="${canjeform.id != null and (canjeform.stOperacion == 'RS' || canjeform.stOperacion == 'CJ')and canjeform.stDocumentoMovArt != 'N'}">
	 	<li>
	 	<fieldset style="width: 400px">
		<legend><fmt:message key="common.filtros"/></legend>
		
	    <div>
	     	<fmt:message key="common.codigo.tarjeta"/><br/>
			<input id="codeTarjetaAnula" class="text medium" name="codeTarjetaAnula" maxlength="12" onblur="obtenerDatosClientePorTarjetaAnulacion(this,true)" />
	    </div><br/>
	    		
			<label for="deCliente" class="required desc">
	        	<fmt:message key="common.nombre"/>
	        </label>	
	        <c:choose>
        
	        	<c:when test="${canjeform.id != null}">
	        		<span id="deClienteAnulaID"><fmt:message key="label.itemdefault"/></span>
	        		<input type="hidden" id="flagClienteAnulaID" name="flagClienteAnula" />
	        	</c:when>
	        	<c:otherwise>
	        
	        	</c:otherwise>
	        </c:choose>	        	        
			    		
		</fieldset>
		</li>
	 </c:if>	
	
	<li>
	<fieldset style="width: 400px">
	<legend><fmt:message key="common.propiedades.generales"/></legend>
		
	    <c:if test="${canjeform.id != null and canjeform.stOperacion == 'RS'}">
	    		<label for="nuDocEntregaReserva" class="required desc">
		        	<fmt:message key="common.doc.entrega.reserva"/>
		        </label>
		        <c:choose>
	        		<c:when test="${canjeform.nuDocEntregaReserva != null and canjeform.nuDocEntregaReserva != ''}">
	        			${canjeform.nuDocEntregaReserva}
	        			<form:hidden path="nuDocEntregaReserva" id="nuDocEntregaReservaID"/><br/>
	        		</c:when>
	        		<c:otherwise>
	        			<form:errors path="nuDocEntregaReserva" cssClass="fieldError"/>
        				<form:input path="nuDocEntregaReserva" id="nuDocEntregaReservaID"
        				cssClass="text medium" maxlength="20" cssErrorClass="text large error"/>
	        		</c:otherwise>
	        	</c:choose>    		
	    </c:if>
		
			<label for="daFechaDocumento" class="required desc">
	        	<fmt:message key="common.fechadoc"/>
	        </label>
	        ${canjeform.daFechaDocumento}
	        <form:hidden path="daFechaDocumento" id="daFechaDocumentoID"/>
		
			<label for="codTarjeta" class="required desc">
	        	<fmt:message key="common.codigo.tarjeta"/> <span class="req">*</span>
	        </label>
	        
	        <c:choose>
	        	<c:when test="${canjeform.id != null}">
	        		${canjeform.codTarjeta}
	        		<form:hidden path="codTarjeta" id="codTarjetaID"/><br/>
	        		
	        		<c:choose>
	        		<c:when test="${canjeform.dePuntosAcumulados != null and canjeform.dePuntosAcumulados != ''}">
	        			<span id="flagTotalPuntos">Total Puntos Acumulados: ${canjeform.dePuntosAcumulados} ptos.</span>
	        		</c:when>
	        		<c:otherwise>
	        			<span id="flagTotalPuntos">Total Puntos Acumulados: 0 ptos.</span>
	        		</c:otherwise>
	        		</c:choose>        		
	        		
	        	</c:when>
	        	<c:otherwise>
	        		<form:errors path="codTarjeta" cssClass="fieldError"/>
	        		<form:input path="codTarjeta" id="codTarjetaID" onblur="obtenerDatosClientePorTarjeta(this,true)"
	        		cssClass="text medium" maxlength="12" cssErrorClass="text large error"/>
	        		<span id="flagTotalPuntos"></span>
	        	</c:otherwise>
	        </c:choose>
		
			<label for="deCliente" class="required desc">
	        	<fmt:message key="common.nombre"/>
	        </label>
	        <c:choose>
	        	<c:when test="${canjeform.id != null}">
	        		<span id="flagCliente">${canjeform.deCliente}</span>
	        		<form:hidden path="deCliente" id="deClienteID"/>
	        	</c:when>
	        	<c:otherwise>
	        		<span id="flagCliente"><fmt:message key="label.itemdefault"/></span>	        
	        		<form:hidden path="deCliente" id="deClienteID"/>
	        	</c:otherwise>
	        </c:choose>	        	        
		
			<label for="coAlmacen" class="required desc">
				<fmt:message key="common.almacen"/>
			</label>
			<c:choose>
	        	<c:when test="${canjeform.id != null}">
	        		${canjeform.deAlmacen}
	        		<form:hidden path="coAlmacen" id="coAlmacenID"/>
					<form:hidden path="deAlmacen" id="deAlmacenID"/>
	        	</c:when>
	        	<c:otherwise>
	        		
	        		<c:choose>
					<c:when test="${not empty listaalmacen}">
						<form:select cssClass="text medium" id="coAlmacenID" path="coAlmacen" >
			        	<form:options itemValue="id" itemLabel="deAlmacen" items="${listaalmacen}"/>
			       		</form:select>
					</c:when>
					<c:otherwise>
						${canjeform.deAlmacen}
						<form:hidden path="coAlmacen" id="coAlmacenID"/>
						<form:hidden path="deAlmacen" id="deAlmacenID"/>
					</c:otherwise>
					</c:choose>
	        		
	        	</c:otherwise>
	        </c:choose>
	        
	        <label for="nuSerie" class="required desc">
				<fmt:message key="common.documento"/> <span class="req">*</span>
			</label>
			<c:choose>
	        	<c:when test="${canjeform.id != null}">
	        		${canjeform.nuSerie} - ${canjeform.nuDocumento}
	        		<form:hidden path="nuSerie" id="nuSerieID"/>
	        		<form:hidden path="nuDocumento" id="nuDocumentoID"/>
	        	</c:when>
	        	<c:otherwise>
	        		<form:select cssClass="text small" id="nuSerieID" path="nuSerie" >
	        			<form:options itemValue="deSerie" itemLabel="deSerie" items="${seriecanje}"/>
	       			</form:select>	       	
	       			<form:input path="nuDocumento" maxlength="20" id="nuDocumentoID" cssClass="text medium" cssErrorClass="text large error"/>
	        	</c:otherwise>
	        </c:choose>
		
			<label for="deObservacion" class="required desc">
				<fmt:message key="common.observaciones"/>
			</label>
			<c:choose>
	        	<c:when test="${canjeform.id != null}">
	        			        		
	        		<c:choose>
	        		<c:when test="${canjeform.deObservacion != null and canjeform.deObservacion != ''}">
	        			${canjeform.deObservacion}
	        			<form:hidden path="deObservacion" id="deObservacionID" />
	        		</c:when>
	        		<c:otherwise>
	        			<fmt:message key="label.itemdefault"/>
	        			<form:hidden path="deObservacion" id="deObservacionID" />
	        		</c:otherwise>
	        		</c:choose>
	        		
	        	</c:when>
	        	<c:otherwise>
	        		<form:textarea path="deObservacion" id="deObservacionID" rows="2" cols="41" onkeypress="isMaxLength(this, 255)"/>
	        	</c:otherwise>
	        </c:choose>
		
	</fieldset></li>

	<li>
	<fieldset style="width: 400px">
	<legend><fmt:message key="common.propiedades.premio"/></legend>
		
			<label for="coCodigoPremio" class="required desc">
	        	<fmt:message key="common.codigo"/> <span class="req">*</span>
	        </label>
	        <c:choose>
	        	<c:when test="${canjeform.id != null}">
	        		${canjeform.coCodigoPremio}
	        		<form:hidden path="coCodigoPremio" id="coCodigoPremioID"/>
	        	</c:when>
	        	<c:otherwise>
	        		<form:errors path="coCodigoPremio" cssClass="fieldError"/>
			        <form:input path="coCodigoPremio" id="coCodigoPremioID" onblur="obtenerDatosPremioPorCodigo(this,true)"
			        cssClass="text medium" maxlength="14" cssErrorClass="text large error"/>
			        
			        <input type="button" class="buttoncal" id="btnModalID" value="..."
			        onclick="openModalPopup()"/>
	        	</c:otherwise>
	        </c:choose>	        
	        
	        <form:hidden path="stManejaSerie" id="stManejaSerieID" />
	        <form:hidden path="stNoManejaStock" id="stNoManejaStockID" />
	        <form:hidden path="stManejaStockPuntoCanje" id="stManejaStockPuntoCanjeID" />	        
	        <form:hidden path="stManejaStockAlmPrincipal" id="stManejaStockAlmPrincipalID" />    
	        
			<label for="deCodigoPremio" class="required desc">
	        	<fmt:message key="common.premio"/>
	        </label>
	        <c:choose>
	        	<c:when test="${canjeform.id != null}">
	        		<span id="flagPremio">${canjeform.deCodigoPremio}</span>
	       	 		<form:hidden path="deCodigoPremio" id="deCodigoPremioID"/>
	        	</c:when>
	        	<c:otherwise>
	        		<span id="flagPremio"><fmt:message key="label.itemdefault"/></span>
	        		<form:hidden path="deCodigoPremio" id="deCodigoPremioID"/>
	        	</c:otherwise>
	        </c:choose>
		
			<label for="vaCantidad" class="required desc">
	        	<fmt:message key="common.cantidad"/> <span class="req">*</span>
	        </label>
	        <c:choose>
	        	<c:when test="${canjeform.id != null}">
	        		${canjeform.vaCantidad}
	        		<form:hidden path="vaCantidad" id="vaCantidadID"/><br/>
	        	</c:when>
	        	<c:otherwise>
	        		<form:errors path="vaCantidad" cssClass="fieldError"/>
	        		<form:input path="vaCantidad" id="vaCantidadID" onblur="calculaTotales()"
	        		cssClass="text medium" maxlength="10" cssErrorClass="text large error"/><br/>
	        	</c:otherwise>
	        </c:choose>    
		
			<div>
            <div class="left" style="width: 170px">
            
			<label for="vaPuntosPremio" class="required desc">
	        	<fmt:message key="common.ptos.premio"/> <span class="req">*</span>
	        </label>
	        <c:choose>
	        	<c:when test="${canjeform.id != null}">
	        		${canjeform.vaPuntosPremio}
	        		<form:hidden path="vaPuntosPremio" id="vaPuntosPremioID"/><br/>
	        	</c:when>
	        	<c:otherwise>
	        		<form:errors path="vaPuntosPremio" cssClass="fieldError"/>
	        		<form:input path="vaPuntosPremio" id="vaPuntosPremioID" onblur="calculaTotales()"
	        		cssClass="text small" maxlength="10" cssErrorClass="text large error"/><br/>
	        	</c:otherwise>
	        </c:choose>
	        </div>
	        <div>
	        	
	        <label for="vaPuntosTotales" class="required desc">
	        	<fmt:message key="common.ptos.total"/>
	        </label>
	        <c:choose>
	        	<c:when test="${canjeform.id != null}">
	        		${canjeform.vaPuntosTotales}
	        		<form:hidden path="vaPuntosTotales" id="vaPuntosTotalesID"/><br/>
	        	</c:when>
	        	<c:otherwise>
	        		<form:errors path="vaPuntosTotales" cssClass="fieldError"/>
	        		<form:input readonly="true" path="vaPuntosTotales" id="vaPuntosTotalesID"
	        		cssClass="text small" cssErrorClass="text large error"/><br/>
	        	</c:otherwise>
	       	</c:choose>   
	        </div>
	        </div>
		
			<div>
            <div class="left" style="width: 170px">
            
			<label for="vaPrecioPremio" class="required desc">
	        	<fmt:message key="common.precio.premio"/> <span class="req">*</span>
	        </label>
	        <c:choose>
	        	<c:when test="${canjeform.id != null}">
	        		${canjeform.vaPrecioPremio}
	        		<form:hidden path="vaPrecioPremio" id="vaPrecioPremioID"/><br/>
	        	</c:when>
	        	<c:otherwise>
	        		<form:errors path="vaPrecioPremio" cssClass="fieldError"/>
	        		<form:input path="vaPrecioPremio" id="vaPrecioPremioID" onblur="calculaTotales()"
	        		cssClass="text small" maxlength="13" cssErrorClass="text large error"/><br/>
	        	</c:otherwise>
	        </c:choose>        
	        </div>
	        <div>
	        
	        <label for="vaPrecioTotal" class="required desc">
	        	<fmt:message key="common.precio.total"/>
	        </label>
	        <c:choose>
	        	<c:when test="${canjeform.id != null}">
	        		${canjeform.vaPrecioTotal}
	        		<form:hidden path="vaPrecioTotal" id="vaPrecioTotalID"/>
	        	</c:when>
	        	<c:otherwise>
	        		<form:errors path="vaPrecioTotal" cssClass="fieldError"/>
	        		<form:input readonly="true" path="vaPrecioTotal" id="vaPrecioTotalID"
	        		cssClass="text small" cssErrorClass="text large error"/>
	        	</c:otherwise>
	       	</c:choose>
	        </div>
	        </div>
		
		<c:choose>
		<c:when test="${canjeform.id == null}">
				<input type="button" class="button" disabled="disabled" id="btnSerieID"
	            onclick="imprimeGrillaSeriePremios()" value="<fmt:message key="common.series"/>"/>			
			<br/>
		</c:when>
		<c:otherwise>
			<c:if test="${canjeform.id != null and canjeform.stOperacion == 'RS'}">
				<c:if test="${canjeform.nuDocEntregaReserva == null or canjeform.nuDocEntregaReserva == ''}">
						<input type="button" class="button" disabled="disabled" id="btnSerieID"
		            	onclick="imprimeGrillaSeriePremios()" value="<fmt:message key="common.series"/>"/>			
					<br/>
				</c:if>
			</c:if>			
		</c:otherwise>
		</c:choose>
		
			<c:choose>
	        	<c:when test="${not empty canjeform.documentoDetalle}">
	        		
	        		<c:choose>
	        		<c:when test="${canjeform.id != null}">
	        		
	        			<table cellpadding="0" id="tableMainSeriesID" class="table" cellspacing="0" style="width: 400px">
	        			<thead>
							<tr>
								<th scope="col"><fmt:message key="common.premio"/></th>
								<th scope="col"><fmt:message key="common.serie"/></th>
							</tr>
						</thead>
						<tbody id="tableSeriesBody">
							<c:forEach var="bncanje" items="${canjeform.documentoDetalle}" varStatus="status">
								<c:choose>
									  <c:when test="${status.index % 2 == 0}"><tr class="odd" ></c:when>
									  <c:otherwise><tr class="even" ></c:otherwise>
								</c:choose>								
								<td>${canjeform.deCodigoPremio}</td>
                				<td>${bncanje.coSerie}</td>
                				</tr>
							</c:forEach>
						</tbody>
	        		</table>
	        		
	        		</c:when>
	        		<c:otherwise>
	        			<table cellpadding="0" id="tableMainSeriesID" class="table" cellspacing="0" style="width: 400px">
	        			<thead>
							<tr>
								<th scope="col"><fmt:message key="common.premio"/></th>
								<th scope="col"><fmt:message key="common.serie"/></th>
							</tr>
						</thead>
						<tbody id="tableSeriesBody">
							<tr id="pattern" style="display:none;">
								<td><span id="tablePremio"></span></td>
								<td><span id="tableSerie" ></span></td>
							</tr>
							<c:forEach var="bncanje" items="${canjeform.documentoDetalle}" varStatus="status">
								<c:choose>
									  <c:when test="${status.index % 2 == 0}"><tr class="odd" ></c:when>
									  <c:otherwise><tr class="even" ></c:otherwise>
								</c:choose>								
								<td>${canjeform.deCodigoPremio}</td>
                				<td>
                				
                				<input type="text" maxlength="50" class="text medium" value="${bncanje.coSerie}"
                				id="documentoDetalle[${status.index}].coSerie" name="documentoDetalle[${status.index}].coSerie" />
                				
                				</td>
                				</tr>
							</c:forEach>
						</tbody>
	        			</table>
	        		
	        		</c:otherwise>
	        		</c:choose>
	        		
	        	</c:when>
	        	<c:otherwise>
	        	
	        		<table cellpadding="0" id="tableMainSeriesID" class="table" cellspacing="0" style="display:none;width: 400px;">
						<thead>
							<tr>
							<th scope="col"><fmt:message key="common.premio"/></th>
							<th scope="col"><fmt:message key="common.serie"/></th>
							</tr>
						</thead>
						<tbody id="tableSeriesBody">
						<tr id="pattern" style="display:none;">
							<td><span id="tablePremio"></span></td>
							<td><span id="tableSerie" ></span></td>
						</tr>
						</tbody>				
					</table>
					
	        	</c:otherwise>
	        </c:choose>
		
	</fieldset>
	</li>
	
	<li>
	<fieldset style="width: 400px">
	<legend><fmt:message key="common.propiedades.direccion.entrega"/></legend>
		
			<c:choose>
	        	<c:when test="${canjeform.id != null}">
	        		
	        		<c:choose>
	        		<c:when test="${canjeform.stDireccion eq 'Y'}">
	        			<fmt:message key="common.direccion"/>
						<form:radiobutton path="strDirEntrega" checked="true" disabled="true" value="direccion" id="strDireccionID" />
	        		</c:when>
	        		<c:otherwise>
	        			<fmt:message key="common.direccion"/>
						<form:radiobutton path="strDirEntrega" disabled="true" value="direccion" id="strDireccionID" />
	        		</c:otherwise>
	        		</c:choose>
	        	
	        		<c:choose>
	        		<c:when test="${canjeform.stAlmacenPrincipal eq 'Y'}">
	        			<fmt:message key="common.almacen"/>
						<form:radiobutton path="strDirEntrega" checked="true" disabled="true" value="almacen" id="strAlmacenID" />
	        		</c:when>
	        		<c:otherwise>
	        			<fmt:message key="common.almacen"/>
						<form:radiobutton path="strDirEntrega" disabled="true" value="almacen" id="strAlmacenID" />
	        		</c:otherwise>
	        		</c:choose>
					
					<c:choose>
	        		<c:when test="${canjeform.stPuntoCanje eq 'Y'}">
	        			<fmt:message key="common.punto.canje"/>
						<form:radiobutton path="strDirEntrega" checked="true" disabled="true" value="puntocanje" id="strPuntoCanjeID" />
	        		</c:when>
	        		<c:otherwise>
	        			<fmt:message key="common.punto.canje"/>
						<form:radiobutton path="strDirEntrega" disabled="true" value="puntocanje" id="strPuntoCanjeID" />
	        		</c:otherwise>
	        		</c:choose>
					
	        	</c:when>
	        	<c:otherwise>
	        		<fmt:message key="common.direccion"/>
					<form:radiobutton path="strDirEntrega" value="direccion" id="strDireccionID" onclick="camposDireccionDesloqueados()"/>
					
					<fmt:message key="common.almacen"/>
					<form:radiobutton path="strDirEntrega" value="almacen" id="strAlmacenID" onclick="camposDireccionBloqueados()"/>
					
					<fmt:message key="common.punto.canje"/>
					<form:radiobutton path="strDirEntrega" value="puntocanje" id="strPuntoCanjeID" onclick="camposDireccionBloqueados()"/>
	        	</c:otherwise>
	        </c:choose>
		
			<label for="deJrAvCa" class="required desc">
	        	<fmt:message key="label.jr"/>
	        </label>
	        <c:choose>
	        	<c:when test="${canjeform.id != null}">
	        		
	        		<c:choose>
	        		<c:when test="${canjeform.deJrAvCa != null and canjeform.deJrAvCa != ''}">
	        			${canjeform.deJrAvCa}
	        			<form:hidden path="deJrAvCa" id="deJrAvCaID" /><br/>
	        		</c:when>
	        		<c:otherwise>
	        			<fmt:message key="label.itemdefault"/>
	        			<form:hidden path="deJrAvCa" id="deJrAvCaID" /><br/>
	        		</c:otherwise>
	        		</c:choose>
	        		
	        		
	        	</c:when>
	        	<c:otherwise>
	        		<form:errors path="deJrAvCa" cssClass="fieldError"/>
	        		<form:input path="deJrAvCa" id="deJrAvCaID" cssClass="text mediumlarge" 
	        		maxlength="50" cssErrorClass="text large error"/><br/>
	        	</c:otherwise>
	        </c:choose>
		
			<label for="deDireccion" class="required desc">
	        	<fmt:message key="common.direccion"/>
	        </label>
	        <c:choose>
	        	<c:when test="${canjeform.id != null}">
	        		
	        		<c:choose>
	        		<c:when test="${canjeform.deDireccion != null and canjeform.deDireccion != ''}">
	        			${canjeform.deDireccion}
	        			<form:hidden path="deDireccion" id="deDireccionID" /><br/>
	        		</c:when>
	        		<c:otherwise>
	        			<fmt:message key="label.itemdefault"/>
	        			<form:hidden path="deDireccion" id="deDireccionID" /><br/>
	        		</c:otherwise>
	        		</c:choose>
	        		
	        		
	        	</c:when>
	        	<c:otherwise>
	        		<form:errors path="deDireccion" cssClass="fieldError"/>
	        		<form:input path="deDireccion" id="deDireccionID" cssClass="text mediumlarge" 
	        		maxlength="50" cssErrorClass="text large error"/><br/>
	        	</c:otherwise>
	        </c:choose>
		
			<div>
            <div class="left" style="width: 170px">
            	<label for="deNumero" class="required desc">
	        		<fmt:message key="common.numero"/>
		        </label>
		        <c:choose>
	        	<c:when test="${canjeform.id != null}">
	        		
	        		<c:choose>
	        		<c:when test="${canjeform.deNumero != null and canjeform.deNumero != ''}">
	        			${canjeform.deNumero}
	        			<form:hidden path="deNumero" id="deNumeroID" /><br/>
	        		</c:when>
	        		<c:otherwise>
	        			<fmt:message key="label.itemdefault"/>
	        			<form:hidden path="deNumero" id="deNumeroID" /><br/>
	        		</c:otherwise>
	        		</c:choose>
	        		
	        		
	        	</c:when>
	        	<c:otherwise>
	        		<form:errors path="deNumero" cssClass="fieldError"/>
		        	<form:input path="deNumero" id="deNumeroID" cssClass="text small" 
		        	maxlength="50" cssErrorClass="text large error"/><br/>
	        	</c:otherwise>
	        </c:choose>     
            </div>
            <div>
            	<label for="deMzLote" class="required desc">
	        		<fmt:message key="label.mz"/>
		        </label>
		        <c:choose>
	        	<c:when test="${canjeform.id != null}">
	        		
	        		<c:choose>
	        		<c:when test="${canjeform.deMzLote != null and canjeform.deMzLote != ''}">
	        			${canjeform.deMzLote}
	        			<form:hidden path="deMzLote" id="deMzLoteID" /><br/>
	        		</c:when>
	        		<c:otherwise>
	        			<fmt:message key="label.itemdefault"/>
	        			<form:hidden path="deMzLote" id="deMzLoteID" /><br/>
	        		</c:otherwise>
	        		</c:choose>
	        		
	        		
	        	</c:when>
	        	<c:otherwise>
	        		<form:errors path="deMzLote" cssClass="fieldError"/>
		        	<form:input path="deMzLote" id="deMzLoteID" cssClass="text small" 
		        	maxlength="50" cssErrorClass="text large error"/><br/>
	        	</c:otherwise>
	        </c:choose>    
            </div>
            </div>
		
			<div>
            <div class="left" style="width: 170px">
            	<label for="deDptoPisoInt" class="required desc">
	        		<fmt:message key="label.dpto"/>
		        </label>
		        <c:choose>
	        	<c:when test="${canjeform.id != null}">
	        		
	        		<c:choose>
	        		<c:when test="${canjeform.deDptoPisoInt != null and canjeform.deDptoPisoInt != ''}">
	        			${canjeform.deDptoPisoInt}
	        			<form:hidden path="deDptoPisoInt" id="deDptoPisoIntID" /><br/>
	        		</c:when>
	        		<c:otherwise>
	        			<fmt:message key="label.itemdefault"/>
	        			<form:hidden path="deDptoPisoInt" id="deDptoPisoIntID" /><br/>
	        		</c:otherwise>
	        		</c:choose>
	        		
	        		
	        	</c:when>
	        	<c:otherwise>
	        		<form:errors path="deDptoPisoInt" cssClass="fieldError"/>
		        	<form:input path="deDptoPisoInt" id="deDptoPisoIntID" cssClass="text small" 
		        	maxlength="50" cssErrorClass="text large error"/><br/>
	        	</c:otherwise>
	        	</c:choose>	        
            </div>
            <div>
            	<label for="deUrbIndResUnVec" class="required desc">
	        		<fmt:message key="label.nombreurb"/>
		        </label>
		        <c:choose>
	        	<c:when test="${canjeform.id != null}">
	        		
	        		<c:choose>
	        		<c:when test="${canjeform.deUrbIndResUnVec != null and canjeform.deUrbIndResUnVec != ''}">
	        			${canjeform.deUrbIndResUnVec}
	        			<form:hidden path="deUrbIndResUnVec" id="deUrbIndResUnVecID" /><br/>
	        		</c:when>
	        		<c:otherwise>
	        			<fmt:message key="label.itemdefault"/>
	        			<form:hidden path="deUrbIndResUnVec" id="deUrbIndResUnVecID" /><br/>
	        		</c:otherwise>
	        		</c:choose>
	        		
	        		
	        	</c:when>
	        	<c:otherwise>
	        		<form:errors path="deUrbIndResUnVec" cssClass="fieldError"/>
		       	 	<form:input path="deUrbIndResUnVec" id="deUrbIndResUnVecID" cssClass="text small" 
		        	maxlength="50" cssErrorClass="text large error"/><br/>
	        	</c:otherwise>
	        	</c:choose>     
            </div>
            </div>
		
			<label for="deSecEtapaZona" class="required desc">
        		<fmt:message key="label.sec"/>
	        </label>
	        <c:choose>
	        	<c:when test="${canjeform.id != null}">
	        		
	        		<c:choose>
	        		<c:when test="${canjeform.deSecEtapaZona != null and canjeform.deSecEtapaZona != ''}">
	        			${canjeform.deSecEtapaZona}
	        			<form:hidden path="deSecEtapaZona" id="deSecEtapaZonaID" /><br/>
	        		</c:when>
	        		<c:otherwise>
	        			<fmt:message key="label.itemdefault"/>
	        			<form:hidden path="deSecEtapaZona" id="deSecEtapaZonaID" /><br/>
	        		</c:otherwise>
	        		</c:choose>
	        		
	        		
	        	</c:when>
	        	<c:otherwise>
	        		<form:errors path="deSecEtapaZona" cssClass="fieldError"/>
	       	 		<form:input path="deSecEtapaZona" id="deSecEtapaZonaID" cssClass="text small" 
	        		maxlength="50" cssErrorClass="text large error"/><br/>
	        	</c:otherwise>
	        	</c:choose>     
		
	        <label for="coDepartamento" class="required desc">
	        	<fmt:message key="label.departamento"/>
	        </label>
	        <c:choose>
	        	<c:when test="${canjeform.id != null}">
	        		
	        		<c:choose>
	        		<c:when test="${canjeform.deDepartamento != null and canjeform.deDepartamento != ''}">
	        			${canjeform.deDepartamento}
	        			<form:hidden path="coDepartamento" id="coDepartamentoID" />
	        			<form:hidden path="deDepartamento" id="deDepartamentoID" /><br/>
	        		</c:when>
	        		<c:otherwise>
	        			<fmt:message key="label.itemdefault"/>
	        			<form:hidden path="coDepartamento" id="coDepartamentoID" />
	        			<form:hidden path="deDepartamento" id="deDepartamentoID" /><br/>
	        		</c:otherwise>
	        		</c:choose>
	        		
	        	</c:when>
	        	<c:otherwise>
	        	
	        		<c:choose>
			        <c:when test="${not empty listadepartamento}">
			        	<form:errors path="coDepartamento" cssClass="fieldError"/>
				        <form:select path="coDepartamento" id="coDepartamentoID" onchange="setCmbProvincia()" cssClass="text mediumlarge" >
			            	<form:options itemValue="coDepartamento" itemLabel="deDepartamento" items="${listadepartamento}"/>
			            </form:select><br/>
				    </c:when>
				    <c:otherwise>
			        	<fmt:message key="label.itemdefault"/><br/>
				    </c:otherwise>
				    </c:choose>
	        	
	        	</c:otherwise>
	        </c:choose>
	    
	        <label for="coProvincia" class="required desc">
	        	<fmt:message key="label.provincia"/>
	        </label>
	        <c:choose>
	        	<c:when test="${canjeform.id != null}">
	        		
	        		<c:choose>
	        		<c:when test="${canjeform.deProvincia != null and canjeform.deProvincia != ''}">
	        			${canjeform.deProvincia}
	        			<form:hidden path="coProvincia" id="coProvinciaID" />
	        			<form:hidden path="deProvincia" id="deProvinciaID" /><br/>
	        		</c:when>
	        		<c:otherwise>
	        			<fmt:message key="label.itemdefault"/>
	        			<form:hidden path="coProvincia" id="coProvinciaID" />
	        			<form:hidden path="deProvincia" id="deProvinciaID" /><br/>
	        		</c:otherwise>
	        		</c:choose>
	        		
	        	</c:when>
	        	<c:otherwise>
	        	
	        		<c:choose>
			        <c:when test="${not empty listaprovincia}">
			        	<form:errors path="coProvincia" cssClass="fieldError"/>
				        <form:select path="coProvincia" id="coProvinciaID" onchange="setCmbDistrito()" cssClass="text mediumlarge" >
			            	<form:options itemValue="coProvincia" itemLabel="deProvincia" items="${listaprovincia}"/>
			            </form:select><br/>
				    </c:when>
				    <c:otherwise>
			        	<fmt:message key="label.itemdefault"/><br/>
				    </c:otherwise>
				    </c:choose>
	        	
	        	</c:otherwise>
	        </c:choose>
	    
	        <label for="coDistrito" class="required desc">
	        	<fmt:message key="label.distrito"/>
	        </label>
	        <c:choose>
	        	<c:when test="${canjeform.id != null}">
	        		
	        		<c:choose>
	        		<c:when test="${canjeform.deDistrito != null and canjeform.deDistrito != ''}">
	        			${canjeform.deDistrito}
	        			<form:hidden path="coDistrito" id="coDistritoID" />
	        			<form:hidden path="deDistrito" id="deDistritoID" /><br/>
	        		</c:when>
	        		<c:otherwise>
	        			<fmt:message key="label.itemdefault"/>
	        			<form:hidden path="coDistrito" id="coDistritoID" />
	        			<form:hidden path="deDistrito" id="deDistritoID" /><br/>
	        		</c:otherwise>
	        		</c:choose>
	        		
	        	</c:when>
	        	<c:otherwise>
	        		
	        		<c:choose>
			        <c:when test="${not empty listadistrito}">
			        	<form:errors path="coDistrito" cssClass="fieldError"/>
				        <form:select path="coDistrito" id="coDistritoID" cssClass="text mediumlarge" >
			            	<form:options itemValue="coDistrito" itemLabel="deDistrito" items="${listadistrito}"/>
			            </form:select><br/>
				    </c:when>
				    <c:otherwise>
			        	<fmt:message key="label.itemdefault"/><br/>
				    </c:otherwise>
				    </c:choose>
	        		
	        	</c:otherwise>
	        </c:choose>
		
	</fieldset></li>
	
	<li class="buttonBar bottom">
        <c:out value="${buttons}" escapeXml="false"/>
    </li>
</ul>

<input type="hidden" id="typeOperationDocument" name="typeOperationDocument" />
</form:form>

<script type="text/javascript">
    Form.focusFirstElement($('canjeform'));
    highlightFormElements();
    window.onload = initCanjeform;
    
	function initCanjeform(){

		var stOperacion = dwr.util.getValue('stOperacionID');
		var idDoc 		= dwr.util.getValue('idDocumentoMovArticulo');
		var codTarjeta  = document.getElementById('codTarjetaID');
		var coCodigoPremio = document.getElementById('coCodigoPremioID');
		var stManejaSerie  = dwr.util.getValue('stManejaSerieID');
		var nuDocEntregaReserva  = dwr.util.getValue('nuDocEntregaReservaID');
		var stDocumentoMovArt = dwr.util.getValue('stDocumentoMovArtID');


			if (stDocumentoMovArt == 'N'){
		    	document.getElementsByName("btnDevolverName")[0].disabled=true;
		    	document.getElementsByName("btnDevolverName")[0].disabled=true;				   	 
			
			} else{
				

				if(idDoc != null && idDoc != '' && stOperacion == 'DC'){
					
					//botones
					document.getElementsByName("btnDevolverName")[0].disabled=true; 
					document.getElementsByName("btnDevolverName")[1].disabled=true; 

				}else if(idDoc != null && idDoc != '' && stOperacion == 'CJ'){
					
					document.getElementsByName("btnDevolverName")[0].disabled=false; 
					document.getElementsByName("btnDevolverName")[1].disabled=false; 
				}
				
			}	
	}

	function setearTipoOperacion(strOperacion){
		dwr.util.setValue("typeOperationDocument",  strOperacion	, { escapeHtml:false });
	}
    
    function onFormSubmit(objForm){

    	var stOperacion = dwr.util.getValue('stOperacionID');
		var idDoc 		= dwr.util.getValue('idDocumentoMovArticulo');

    	if(idDoc != null && idDoc != '' && stOperacion == 'RS'){
    		var nuDocEntregaReserva	= dwr.util.getValue('nuDocEntregaReservaID');
    		if(nuDocEntregaReserva == null || trim(nuDocEntregaReserva) == ''){
				alert('El campo Documento Entrega Reserva es obligatorio.');
				return false;
        	}
        }        

    	var isSubmit = validateCanjeform(objForm) && 
    	validaDetalleDocumentoCanje();

		if(isSubmit != false){
			isSubmit = true;
		}
    	
    	if(isSubmit){
        	
    		var action = document.getElementById('typeOperationDocument');
        	 if(action == 'CJ'){
        		document.getElementsByName("btnDevolverName")[0].disabled=true;
	  			document.getElementsByName("btnDevolverName")[1].disabled=true;

       		 }            
	  		
	  		return true;
		}

		return false;
    }

    function validaDetalleDocumentoCanje(){

    	var stOperacion = dwr.util.getValue('stOperacionID');
		var idDoc 		= dwr.util.getValue('idDocumentoMovArticulo');
    	var vaCantidad  = trim(dwr.util.getValue('vaCantidadID'));
    	var stManejaSerie = dwr.util.getValue('stManejaSerieID');
    	var stManejaStockPuntoCanje = dwr.util.getValue('stManejaStockPuntoCanjeID');

    	if(idDoc != null && idDoc != '' && stOperacion == 'RS' && 
    	   stManejaSerie == 'Y' && trim(vaCantidad) != '' && !isNaN(vaCantidad)){

    		for (var i = 0; i < vaCantidad; i++) {

				var detalle = document.getElementById("documentoDetalle["+i+"].coSerie");
				if(detalle == null){
					alert('La grilla detalle de las series para el premio es obligatoria.');
					return false;
				}else{
					if(trim(detalle.value) == ''){
						alert('Todos los campos series de la grilla detalle son obligatorios.');
						return false;
					}
				}				
			}

			return true;
			
        }else{
        	if(stManejaSerie == 'Y' &&
      		   stManejaStockPuntoCanje == 'Y' && 
      		   !isNaN(vaCantidad) && trim(vaCantidad) != ''){
      				
   				for (var i = 0; i < vaCantidad; i++) {

   					var detalle = document.getElementById("documentoDetalle["+i+"].coSerie");
   					if(detalle == null){
   						alert('La grilla detalle de las series para el premio es obligatoria.');
   						return false;
   					}else{
   						if(trim(detalle.value) == ''){
   							alert('Todos los campos series de la grilla detalle son obligatorios.');
   							return false;
   						}
   					}				
   				}
   			}

   			return true;
        }
    }

    function imprimeGrillaSeriePremios(){
	
    	var btnSerie 	   = document.getElementById("btnSerieID").disabled;
    	var vaCantidad	   = trim(document.getElementById('vaCantidadID').value);
    	var deCodigoPremio = trim(document.getElementById("deCodigoPremioID").value);
    	var tableMainSerie = document.getElementById("tableMainSeriesID").style;    	

    	//el boton este desbloqueado y cantidad sea un numero
    	if(btnSerie == false && !isNaN(vaCantidad) && trim(vaCantidad) != ''){

    		dwr.util.removeAllRows("tableSeriesBody", { filter:function(tr) {
      	    return (tr.id != "pattern");}});

    		var inputText = '';
    		var contador  = 0;
    		for (var i = 1; i <= vaCantidad; i++) {

    			inputText = "<input id=\"documentoDetalle["+contador+"].coSerie\" 	   "+
    			"name=\"documentoDetalle["+contador+"].coSerie\" class=\"text medium\" "+
    			"type=\"text\" maxlength=\"50\" />"; 
    			
    	      	dwr.util.cloneNode("pattern", { idSuffix: i });
    	      	dwr.util.setValue("tablePremio" + i,  deCodigoPremio, { escapeHtml:false });    	      	
    	      	dwr.util.setValue("tableSerie"  + i,  inputText		, { escapeHtml:false });
    	      	
				if(i % 2 == 0){
					$("pattern" + i).className = "odd";
				}
				else{
					$("pattern" + i).className = "even";
				}
	    	      
	    	    $("pattern" + i).style.display = "";
	    	    tableMainSerie.display = "";
	    	    contador = contador + 1;
    	    }
    		
        }else{
        	tableMainSerie.display = "none";
        }
    }

    
    function camposDireccionBloqueados(){

    	document.getElementById('deJrAvCaID').disabled=true;
    	document.getElementById('deDireccionID').disabled=true;
    	document.getElementById('deNumeroID').disabled=true;
    	document.getElementById('deMzLoteID').disabled=true;
    	document.getElementById('deDptoPisoIntID').disabled=true;
    	document.getElementById('deUrbIndResUnVecID').disabled=true;
    	document.getElementById('deSecEtapaZonaID').disabled=true;
    	document.getElementById('coDepartamentoID').disabled=true;
    	document.getElementById('coProvinciaID').disabled=true;
    	document.getElementById('coDistritoID').disabled=true;

    	document.getElementById('deJrAvCaID').value="";
    	document.getElementById('deDireccionID').value="";
    	document.getElementById('deNumeroID').value="";
    	document.getElementById('deMzLoteID').value="";
    	document.getElementById('deDptoPisoIntID').value="";
    	document.getElementById('deUrbIndResUnVecID').value="";
    	document.getElementById('deSecEtapaZonaID').value="";
    }

    function camposDireccionDesloqueados(){

    	document.getElementById('deJrAvCaID').disabled=false;
    	document.getElementById('deDireccionID').disabled=false;
    	document.getElementById('deNumeroID').disabled=false;
    	document.getElementById('deMzLoteID').disabled=false;
    	document.getElementById('deDptoPisoIntID').disabled=false;
    	document.getElementById('deUrbIndResUnVecID').disabled=false;
    	document.getElementById('deSecEtapaZonaID').disabled=false;
    	document.getElementById('coDepartamentoID').disabled=false;
    	document.getElementById('coProvinciaID').disabled=false;
    	document.getElementById('coDistritoID').disabled=false;
    }

    function setCmbProvincia(){

    	var coDepartamento = dwr.util.getValue("coDepartamentoID");
    	if(coDepartamento != '-1' && coDepartamento != null){
        	
	    	dwr.util.useLoadingMessage("Cargando ...");
	    	dwr.util.removeAllOptions("coProvinciaID");
			
	    	AfiliacionService.findPronvinciaUbigeo(coDepartamento,false,
	    	function(data) {

	    		dwr.util.addOptions("coProvinciaID", data,"coProvincia","deProvincia");
	    		var obj = new Object();
	    		obj 	= data[0];
	    			    		
	    		dwr.util.removeAllOptions("coDistritoID");
	    		AfiliacionService.findDistritoUbigeo(coDepartamento,obj.coProvincia,false,
   		    	function(datos) {
   		    		dwr.util.addOptions("coDistritoID", datos,"coDistrito","deDistrito");          	
   		    	});
	    	});
    	}
    }

    function setCmbDistrito(){

    	var coDepartamento = dwr.util.getValue("coDepartamentoID");
    	var coProvincia    = dwr.util.getValue("coProvinciaID");
		if(coProvincia != '-1' && coProvincia != null &&
				coDepartamento != '-1' && coDepartamento != null){
        	
	    	dwr.util.useLoadingMessage("Cargando ...");
	    	dwr.util.removeAllOptions("coDistritoID");
			
	    	AfiliacionService.findDistritoUbigeo(coDepartamento,coProvincia,false,
	    	function(data) {
	    		dwr.util.addOptions("coDistritoID", data,"coDistrito","deDistrito");          	
	    	});
    	}
    }

    function calculaTotales(){

    	var vaPrecioPremio = document.getElementById('vaPrecioPremioID').value;    	
    	var vaPuntosPremio = document.getElementById('vaPuntosPremioID').value;
    	var vaCantidad	   = document.getElementById('vaCantidadID').value;
    	
    	var vaPrecioTotal = '0.0';
    	var vaPuntosTotal = '0.0';

		if((trim(vaPrecioPremio) != '' && trim(vaPuntosPremio) != '' && trim(vaCantidad) != '') &&		   
		   (!isNaN(vaPrecioPremio) && !isNaN(vaPuntosPremio) && !isNaN(vaCantidad))){

			vaPrecioPremio = trim(vaPrecioPremio);
			vaPuntosPremio = trim(vaPuntosPremio);
			vaCantidad 	   = trim(vaCantidad);
			
			vaPrecioTotal = parseFloat(vaCantidad) * parseFloat(vaPrecioPremio);
			vaPuntosTotal = parseFloat(vaCantidad) * parseFloat(vaPuntosPremio);	
		}
    	
    	dwr.util.setValue("vaPuntosTotalesID", vaPuntosTotal, { escapeHtml:false });
		dwr.util.setValue("vaPrecioTotalID"	 , vaPrecioTotal, { escapeHtml:false });
    }

    function obtenerDatosClientePorTarjeta(obj,flag){

		var codeTarjeta = obj.value;
		if(codeTarjeta != null && trim(codeTarjeta) != ''){

			dwr.util.useLoadingMessage("Cargando ...");
			CanjeService.obtenerDatosClientePorTarjeta(codeTarjeta, function(data) {

				var puntosacumulados = 'Total Puntos Acumulados: ';				
				if(data.dePuntosAcumulados == null || trim(data.dePuntosAcumulados) == ''){
					puntosacumulados = puntosacumulados + '0 ptos.';
				}else{
					puntosacumulados = puntosacumulados + data.dePuntosAcumulados +' ptos.';
				}

				if(data.deNombre != null && trim(data.deNombre) != ''){
					dwr.util.setValue("deClienteID", data.deNombre, { escapeHtml:false });
					dwr.util.setValue("flagCliente", data.deNombre, { escapeHtml:false });
					dwr.util.setValue("flagTotalPuntos", puntosacumulados, { escapeHtml:false });
				}else{
					dwr.util.setValue("deClienteID", '', { escapeHtml:false });
					dwr.util.setValue("flagCliente", '----', { escapeHtml:false });
					dwr.util.setValue("flagTotalPuntos", '', { escapeHtml:false });

					if(flag){
						alert('No se encontro un cliente relacionado a la tarjeta');
						return false;
					}
				}
			});			
		}
    }


    function obtenerDatosClientePorTarjetaAnulacion(obj,flag){

		var codeTarjeta = obj.value;
		if(codeTarjeta != null && trim(codeTarjeta) != ''){

			dwr.util.useLoadingMessage("Cargando ...");
			CanjeService.obtenerDatosClientePorTarjeta(codeTarjeta, function(data) {

				if(data.coClientePersona != null && trim(data.coClientePersona) != ''){
					dwr.util.setValue("deClienteAnulaID", data.deNombre, { escapeHtml:false });
					dwr.util.setValue("flagClienteAnulaID", data.coClientePersona, { escapeHtml:false });
					
				}else{
					dwr.util.setValue("deClienteAnulaID", '<fmt:message key="label.itemdefault"/>', { escapeHtml:false });
					dwr.util.setValue("flagClienteAnulaID",'' , { escapeHtml:false });
						if(flag){
						alert('No se encontro un cliente relacionado a la tarjeta');
						return false;
					}
				}
			});			
		}
    }
    
    function obtenerDatosPremioPorCodigo(obj,flag){

    	var idDoc = dwr.util.getValue('idDocumentoMovArticulo');
    	var coAlmacen = dwr.util.getValue('coAlmacenID');
    	
    	var codePremio = obj.value;
    	if(codePremio != null && trim(codePremio) != ''){

    		dwr.util.useLoadingMessage("Cargando ...");
    		document.getElementById("btnSerieID").disabled=true;

			if(flag){
    			imprimeGrillaSeriePremios();
			}
    		
    		CanjeService.obtenerDatosPremioPorCodigo(codePremio,coAlmacen, function(data) {
    			dwr.util.setValue("deCodigoPremioID", data.deArticulo, { escapeHtml:false });
    			dwr.util.setValue("stManejaSerieID", data.stManejaSerie, { escapeHtml:false });
    			dwr.util.setValue("stNoManejaStockID", data.stNoManejaStock, { escapeHtml:false });
    			dwr.util.setValue("stManejaStockPuntoCanjeID", data.stManejaStockPuntoCanje, { escapeHtml:false });
    			dwr.util.setValue("stManejaStockAlmPrincipalID", data.stManejaStockAlmPrincipal, { escapeHtml:false });
    			dwr.util.setValue("vaPuntosPremioID", data.vaPuntosRequeridos, { escapeHtml:false });
    			dwr.util.setValue("vaPrecioPremioID", data.vaMontoRequerido, { escapeHtml:false });

    			calculaTotales();
        		if((idDoc == null || idDoc == '') && //si es insertar y es una reserva
                   (data.stManejaStockPuntoCanje != 'Y')){
        			document.getElementById("btnSerieID").disabled=true;
        			imprimeGrillaSeriePremios();
            	}else{
            		if(data.stManejaSerie == 'Y'){
        				document.getElementById("btnSerieID").disabled=false;
            		}
                }

    			if(data.deArticulo != null && trim(data.deArticulo) != ''){
					dwr.util.setValue("flagPremio", data.deArticulo, { escapeHtml:false });
				}else{
					dwr.util.setValue("flagPremio", '----', { escapeHtml:false });

					if(flag){
						alert('No se encontro un articulo relacionado al codigo de premio y el almacen.');
						return false;
					}
				}

    			if(data.stManejaStockPuntoCanje == 'Y'){
    				manejaStockPuntoCanje();
    			}else if(data.stManejaStockAlmPrincipal == 'Y'){
					manejaStockAlmPrincipal();
            	}else if(data.stNoManejaStock == 'Y'){
					noManejaStock();
                }        		
    		});
       	}else{
           	
       		dwr.util.setValue("flagPremio", '----', { escapeHtml:false });
			dwr.util.setValue("deCodigoPremioID", "", { escapeHtml:false });
        	dwr.util.setValue("vaCantidadID"	, "", { escapeHtml:false });
        	dwr.util.setValue("vaPrecioPremioID", "", { escapeHtml:false });
        	dwr.util.setValue("vaPuntosPremioID", "", { escapeHtml:false });
        	dwr.util.setValue("vaPuntosTotalesID", "0.0", { escapeHtml:false });
    		dwr.util.setValue("vaPrecioTotalID"	 , "0.0", { escapeHtml:false });
       	}
    }


    function openModalPopup(){

    	var idDoc 	  = dwr.util.getValue('idDocumentoMovArticulo');
		var coAlmacen = document.getElementById('coAlmacenID').value;    	
    	Modalbox.show('<c:url value="/canje/buscarpremios.html?coalmacen='+coAlmacen+'"/>',{
        	title		: this.title,
    		width		: 930,
    		height		: 490,
   			afterHide: function(){

   				calculaTotales();
   				var stManejaSerie = dwr.util.getValue("stManejaSerieID");
   				var deCodigoPremio = dwr.util.getValue("deCodigoPremioID");
   				var stNoManejaStock = dwr.util.getValue("stNoManejaStockID");
   				var stManejaStockPuntoCanje = dwr.util.getValue("stManejaStockPuntoCanjeID");
   				var stManejaStockAlmPrincipal = dwr.util.getValue("stManejaStockAlmPrincipalID");
   				
   				if(deCodigoPremio != null && trim(deCodigoPremio) != ''){
   					dwr.util.setValue("flagPremio", deCodigoPremio, { escapeHtml:false });
				}else{
					dwr.util.setValue("flagPremio", '----', { escapeHtml:false });
				}

   				if((idDoc == null || idDoc == '') && //si es insertar y es una reserva
	               (stManejaStockPuntoCanje != 'Y')){
	       			document.getElementById("btnSerieID").disabled=true;
	       			imprimeGrillaSeriePremios();
   	            }else{
   	            	if(stManejaSerie == 'Y'){
   	    				document.getElementById("btnSerieID").disabled=false;
   	        		}else{
   	        			document.getElementById("btnSerieID").disabled=true;
   	        			imprimeGrillaSeriePremios();
   	            	}
   	   	        }   				

   				if(stManejaStockPuntoCanje == 'Y'){
    				manejaStockPuntoCanje();
    			}else if(stManejaStockAlmPrincipal == 'Y'){
					manejaStockAlmPrincipal();
            	}else if(stNoManejaStock == 'Y'){
					noManejaStock();
                }
 	    	}
    	});
    }




    function devolucionCliente(){

		var codeTarjeta = document.getElementById("codeTarjetaAnula").value;
		var id = document.getElementById("idDocumentoMovArticulo").value;
		var coCodigoPremio = document.getElementById("coCodigoPremioID").value;
		var idCliente = document.getElementById("flagClienteAnulaID").value;
		var coClienteID = document.getElementById("coClienteID").value;

				
		if(idCliente != null && trim(idCliente) != ''){

			dwr.util.useLoadingMessage();
			CanjeService.obtenerDatosClientePorTarjeta(codeTarjeta, function(data) {

				if(data.deNombre != null && trim(data.deNombre) != ''){
					var url = "/clubpgnweb/devolucioncliente/devolucionclienteform.html?id="+ id;
					window.location.href = url;
				}else{
						alert('No se encontro un cliente relacionado a la tarjeta');
						return false;
				}
			});			
		} else {
			alert('Ingrese el codigo de tarjeta del cliente para devolver el premio');
			return false;
			}        
		

					
	}    
</script>
<v:javascript formName="canjeform" staticJavascript="false"/>
<script type="text/javascript" src="<c:url value="/scripts/validator.jsp"/>"></script>
<script type='text/javascript' src="<c:url value="/dwr/interface/CanjeService.js"/>"></script>
<script type='text/javascript' src="<c:url value="/dwr/interface/AfiliacionService.js"/>"></script>